import java.util.Random;
import java.util.Scanner;

public class NGuessNumber
{
    public static void main(String[] args)
    {
        A:while(true)
        {
            System.out.println("<------开始游戏------>");
            int[] daan = generateAnswer();
            B:for(int a = 0 ; a<7 ; a++)
            {
                System.out.println("请输入4个数字:");
                int[] cai = getPlayerInput();
                boolean jg = isWin(compareGuessAnswer(daan,cai));
                if(jg)
                {
                    System.out.println("你赢了");
                    break B;
                }
            }
            System.out.println("再玩一局输入1,结束游戏输入0:");
            int pd = new Scanner(System.in).nextInt();
            if(pd == 0)
            {
                break A;
            }
            else if(pd == 1) {}
            else
            {
                System.out.println("程序出现错误,结束运行");
                break A;
            }
        }
    }
    public static boolean isWin(boolean[] booleans) {
        if (booleans[0] && booleans[1] && booleans[2] && booleans[3]) {
            return true;
        }
        return false;
    }
    public static boolean[] compareGuessAnswer(int[] arr1,int[] arr2)
    {
        boolean[] bool = new boolean[4];
        for(int a = 0 ; a<4 ; a++)
        {
            if(arr1[a] == arr2[a])
            {
                System.out.println("第"+(a+1)+"个数猜对了");
                bool[a] = true;
            }
            else
            {
                if(arr2[a] > arr1[a])
                {
                    System.out.println("第"+(a+1)+"个数猜大了");
                }
                else
                {
                    System.out.println("第"+(a+1)+"个数猜小了");
                }
                bool[a] = false;
            }
        }
        return bool;
    }
    public static int[] getPlayerInput()
    {
        int[] arr = new int[4];
        Scanner scan = new Scanner(System.in);
        for(int a = 0 ; a<arr.length ; a++)
        {
            arr[a] = scan.nextInt();
        }
        return arr;
    }
    public static int[] generateAnswer()
    {
        int[] arr = new int[4];
        Scanner scan = new Scanner(System.in);
        for (int a = 0 ; a<arr.length ; a++)
        {
            if(a == 0)
            {
                arr[a] = addNumber();
            }
            else
            {
                while(true)
                {
                    int ls = addNumber();
                    if(NoCF(ls,arr,a))
                    {
                        arr[a] = ls;
                        break;
                    }
                }
            }
        }
        return arr;
    }
    public static int addNumber()
    {
        return new Random().nextInt(9);
    }
    public static boolean NoCF(int yz,int[] arr,int xb)
    {
        for(int a = 0 ; a<xb ; a++)
        {
            if(yz == arr[a])
            {
                return false;
            }
        }
        return true;
    }
}
